/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.schedule.executor.daemon;

import org.quartz.SchedulerException;

import com.hyts.schedule.executor.base.BaseSchedulerManager;
import com.hyts.schedule.executor.config.DefaultJobConfig;
import com.hyts.schedule.executor.error.ScheduleError;
import com.hyts.schedule.executor.executor.DefaultScheduleExecutor;

/** 
 * @title MonitorSchedule.java  
 * @package com.hyts.schedule.quartz.daemon  
 * @description TODO  
 * @see TODO
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年5月19日 
 * @version V1.0 
 */
public class MonitorSchedule implements Runnable{
	
	private String name ;
	private DefaultScheduleExecutor executor;
	
	
	/**  
	 * @constructor：MonitorSchedule  
	 * @param name  
	 */ 
	public MonitorSchedule(String name,DefaultScheduleExecutor executor) {
		super();
		this.name = name;
		this.executor = executor;
	}



	/* (非 Javadoc)
	 * @see java.lang.Runnable#run()  
	 * @exception
	 */ 
	@Override
	public void run() {
		try {
			while(BaseSchedulerManager.getInstance().getJobGroupNames() != null && 
					BaseSchedulerManager.getInstance().getJobGroupNames().size() != 0){
				System.out.println("后台守护线程: Domain"+this.name+"正在轮训监控!");
				Thread.sleep(DefaultJobConfig.DEFAULT_MONITOR_THREAD_INTERVAL);
			}
			System.out.println("后台守护线程: Domain"+this.name+"监控到调度器空闲，自动关闭调度器！");
			BaseSchedulerManager.getInstance().shutdown(true);
		} catch (SchedulerException | InterruptedException e) {
			throw new ScheduleError(e);
		}
	}
}
